<?php

class RedisConfig
{
    public static $hosts = [
        'localhost' => ['127.0.0.1', 6379, ''],
    ];

    //队列信息, r:read, w:write; 用法:
    //1. 从read队列读取数据, 处理完毕后, 将结果写到write队列, 如果不需要将结果写队列, 可以不用填写write队列名
    //2. 将消息写入到write队列, 从read队列接收处理结果, 如果不需要接收处理结果, 可以不用填写read的队列名
    public static $queueList = [
        'test' => ['r' => 'test', 'w' => 'test_cb'],
        'log' => ['r' => '', 'w' => 'redis_log'],
    ];

    //读取消息后, 调用指定的类,方法去处理消息:
    //键名为消息体中_callback字段的值
    public static $queueCallBack = [
        'store_image_upload' => ['class'=> 'xxx', 'method' => 'uploadImage'],
    ];

    //获取回调方法名
    public static function getCallBack($key)
    {
        if (!empty(self::$queueCallBack[$key])) {
            return self::$queueCallBack[$key];
        } else {
            return false;
        }
    }

    //获取某个项目的队列名
    public static function getQueueKey($project, $type='w')
    {
        if (!empty(self::$queueList[$project][$type])) {
            return self::$queueList[$project][$type];
        } else {
            return false;
        }
    }

    //获取所有的读队列
    public static function getAllQueueKeyRead()
    {
        $list = [];
        foreach (self::$queueList as $v) {
            $list[] = $v['r'];
        }

        $list = array_filter($list);
        $list = array_unique($list);
        return $list;
    }

    //获取所有的写队列
    public static function getAllQueueKeyWrite()
    {
        $list = [];
        foreach (self::$queueList as $v) {
            $list[] = $v['w'];
        }

        $list = array_filter($list);
        $list = array_unique($list);
        return $list;
    }

}